//
//  statuses.swift
//  weibo1
//
//  Created by Apple on 15/12/1.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit

class statuses: NSObject {
    ///微博创建时间
    var created_at: String?
    //微博ID
    var id: Int = 0
    //微博正文
    var text: String?
    //微博来源
    var source: String?
    //添加user属性
    var user : UserName?
    
    //转发的微博属性
    var retweeted_status: statuses?
    
    var pic_urls: [[String : String]]? {
        
        didSet{
            if let url = pic_urls {
                //实例化imageUrl
                imageUrl = [NSURL]()
                for item in url{
                    
                    let urlstring = item ["thumbnail_pic"]
                    let urls = NSURL(string: urlstring!)!
                    
                    imageUrl?.append(urls)
                }
            }
            return
        }
        
    }
    
    
    //添加配图属性
    var imageUrl: [NSURL]?
    
    
    //KVC构造方法
    init(dict: [String : AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
         //判断user键 对应的value  能否转化为 User(dict  对应的字典
        if key == "user" {
            
            if let dict = value as? [String : AnyObject]{
                user = UserName(dict: dict)
            }
        return
        }
        
        if key == "retweeted_status" {
            
            if let dict = value as? [String : AnyObject]{
                retweeted_status = statuses(dict: dict)
            }
            return
        }
        
        
        super.setValue(value, forKey: key)
        
    }
    
    
    
   override func setValue(value: AnyObject?, forUndefinedKey key: String) {
    }
    
   override var description: String{
        
        let key = ["created_at","id","source","text"]
    return dictionaryWithValuesForKeys(key).description
    }
}
